<?php

namespace App\Admin\Controllers;

use App\Services\UpCustomerService;
use Slowlyo\OwlAdmin\Controllers\AdminController;

/**
 * 上游管理
 *
 * @property UpCustomerService $service
 */
class UpCustomerController extends AdminController
{
	protected string $serviceName = UpCustomerService::class;

	public function list()
	{
		$crud = $this->baseCRUD()
			->filterTogglable(false)
			->headerToolbar([
				$this->createButton('dialog'),
				...$this->baseHeaderToolBar()
			])
			->columns([
				amis()->TableColumn('id', 'ID')->sortable(),
				amis()->TableColumn('short_name', '供应商简称'),
				amis()->TableColumn('customer_name', '供应商名称'),
				amis()->TableColumn('type_id', '分类')->type('mapping')->map([
					1 => "<span class='label label-success'>供应商(同行)</span>",
					2 => "<span class='label label-danger'>运营商</span>",
					3 => "<span class='label label-warning'>其他</span>",
				]),
				amis()->TableColumn('bd_uid.name', '对接人')->sortable(),
				amis()->TableColumn('bd_email', '对接邮箱'),
				// amis()->TableColumn('sign_company.company_name', '签约公司'),
				amis()->TableColumn('business_email', '商务邮箱'),
				amis()->TableColumn('customer_address', '供应商地址'),
				amis()->TableColumn('created_at', admin_trans('admin.created_at'))->type('datetime')->sortable(),
				
				$this->rowActions('dialog')
			]);

		return $this->baseList($crud);
	}

	public function form($isEdit = false)
	{
		return $this->baseForm()->body([
			amis()->TextControl('short_name', '简称'),
			amis()->TextControl('customer_name', '公司名称'),
			amis()->SelectControl('type_id', '分类')
				->options([
					['label' => '供应商(同行)', 'value' => 1],
					['label' => '运营商', 'value' => 2],
					['label' => '其他', 'value' => 3],
				]),
			amis()->SelectControl('bd_uid', '对接人')
				->source('/system/admin_users?_action=getData')
				->labelField('name')
				->valueField('id'),
			amis()->GroupControl()->body([
				amis()->TextControl('bd_email', '对接邮箱'),
				amis()->TextControl('customer_address', '地址'),
			]),
			
			amis()->GroupControl()->body([
				amis()->TextControl('business_email', '商务邮箱'),
				amis()->TextControl('ops_email', '运维邮箱'),
			]),
			amis()->GroupControl()->body([
				amis()->TextControl('violation_email', '违规邮箱'),
				amis()->TextControl('cutover_email', '割接邮箱'),
			]),
	
			
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('bd_uid', '对接人')->static(),
			amis()->TextControl('business_email', '商务邮箱')->static(),
			amis()->TextControl('customer_address', '供应商地址')->static(),
			amis()->TextControl('customer_name', '供应商名称')->static(),
			amis()->TextControl('cutover_email', '割接邮箱')->static(),
			amis()->TextControl('editor_uid', '编辑人UID')->static(),
			amis()->TextControl('is_delete', '是否删除：0-未删除 1-已删除')->static(),
			amis()->TextControl('operator_uid', '操作人UID')->static(),
			amis()->TextControl('ops_email', '运维邮箱')->static(),
			amis()->TextControl('short_name', '供应商简称')->static(),
			amis()->TextControl('sign_company', '签约公司')->static(),
			amis()->TextControl('violation_email', '违规邮箱')->static(),
			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
		]);
	}
}